<extend name="Public/index"/>
<block name="content">
<link rel="stylesheet" href="http://static.runoob.com/assets/foundation-icons/foundation-icons.css">
<link rel="stylesheet" href="__JS__">
	<!-- <input type="text" id="datetimepicker2"/> -->
	<br>
	<div class='row'>
		<form action="?" method="post" id='form'>
			<div class='medium-4 columns'>
				<input id="datetimepicker2" type="text" name='points_time' value='<{$time}>'>
			</div>
			<div class='medium-4 columns'>
				<select name="term_id" id="term_id">
					<volist name='term' id='vo'>
						<option value="<{$vo.val}>" <{$nowTerm == $vo['val']?'selected':null}>><{$vo.val}></option>
					</volist>
				</select>
			</div>
			<div class='medium-4 columns'>
				<input type="text" name='sname' id='sname' value='<{$sname}>'>
			</div>
		</form>
	</div>
	<div class="row">
		
			<table class='medium-12 columns'>
				<tr>
					<th>姓名</th>
					<volist name='article' id='articleTitle'>
						<th><{$articleTitle.rule_name}></th>
					</volist>
				</tr>
				<volist name='student' id='vo'>
					<tr index='<{$vo.student_id}>'>
					<th><{$vo.sname}></th>
					<volist name='article' id='vv'>
						<td index='<{$vv.points_rules_id}>'></td>
					</volist>
					</tr>
				</volist>
			</table>
		
	</div>
	<script src='__DATE__'></script>
	<script>
	var arr = <{$pointJson}>;
	for(index in arr){
		var s = null;
		s = arr[index]['student_id'];
		a = arr[index]['points_rules_id'];
		id = arr[index]['points_id'];
		$('tr[index='+s+'] td[index='+a+']').attr('id',id).html('<i class="fi-check"></i>');
	}
	$('table tr td').click(function(){
		var i,
			s,
			a,
			id,
			data = {};
			if($(this).html()){
				unCheck(this);
			}else{
				check(this);
			}
	});
	var check = function(e){
		time = $('#datetimepicker2').val();
		i = document.createElement('i');
		$(i).prop('class','fi-check');
		$(e).html(i);
		s = $(e).parents('tr').attr('index');
		a = $(e).attr('index');
		data = {student_id:s,points_rules_id:a,points_time:time};
		$.post("<{:U('deduct')}>",data,function(data){
			$(e).attr('id',data);
		});
	}
	var unCheck = function(e){
		id = $(e).attr('id');
		console.log(id);
		$(e).html(null);
		data = {id:id};
		$.post("<{:U('editCredit')}>",data,function(data){

		});
	}
	$("#datetimepicker2,#term_id,#sname").blur(function(){
		$('#form').submit();
	});
	$('#datetimepicker2').datetimepicker({
		lang:'ch',
		timepicker:false,
		format:'Y-m-d',
		formatDate:'Y/m/d',
		minDate:'2000/01/01', // yesterday is minimum date
		maxDate:'2020/12/31' // and tommorow is maximum date calendar
	});
	</script>
</block>